package com.joyxy.spider.mapscript.operation;

/**
 * 基础操作抽象类
 * 所有具体操作类的父类
 */
public abstract class BaseOperation {
    /** 操作类型 */
    protected int operationType;
    /** 操作描述 */
    protected String description;
    
    public BaseOperation(int operationType, String description) {
        this.operationType = operationType;
        this.description = description;
    }
    
    /**
     * 获取操作类型
     */
    public int getOperationType() {
        return operationType;
    }
    
    /**
     * 获取操作描述
     */
    public String getDescription() {
        return description;
    }
    
    /**
     * 执行操作 - 由子类实现具体逻辑
     */
    public abstract void execute();
    
    /**
     * 验证操作参数是否有效
     */
    public abstract boolean isValid();
    
    /**
     * 获取操作的详细信息
     */
    public abstract String getDetailInfo();
    
    /**
     * 从ScriptOperation创建具体的操作对象
     */
    public static BaseOperation createOperation(int operationType, int[] parameters) {
        switch (operationType) {
            case 1: // 水平移动
                return HorizontalMoveOperation.fromParameters(parameters);
            case 2: // 垂直移动
                return VerticalMoveOperation.fromParameters(parameters);
            case 3: // 跳跃
                return JumpOperation.fromParameters(parameters);
            case 4: // 地图转换
                return MapChangeOperation.fromParameters(parameters);
            case 5: // 吹怪
                return LureMonsterOperation.fromParameters(parameters);
            case 6: // 攻击
                return AttackOperation.fromParameters(parameters);
            default:
                return new UnknownOperation(operationType, parameters);
        }
    }
    
    @Override
    public String toString() {
        return String.format("%s{type=%d, desc='%s'}", 
                getClass().getSimpleName(), operationType, description);
    }
} 